public class HashBucket {
     static class Node {
         public int key;
         public int val;
         public Node next;
         public Node(int key, int val) {
             this.key = key;
             this.val = val;
         }
     }
     public Node[] array;
     public int HashSizi;//插入个数
    public HashBucket() {
         this.array=new Node[10];
         this.HashSizi=0;
    }
    public void put(int key,int val) {
        int index = key % array.length;
        Node ret = array[index];
        if(ret==null) {
            Node str =new Node(key,val);
            array[index] =str;
            this.HashSizi++;
            return;
        }
        Node uer =null;
        //先判断表里有无这个key映射
        while(ret!=null) {
            uer =ret;
            if(ret.key==key) {//代表有相对映射了，要改val
                ret.val=val;
                this.HashSizi++;
                return;
            }
            ret=ret.next;
        }
        Node str =new Node(key,val);
        uer.next =str;
        this.HashSizi++;
        if(Size()>=0.75) {//如果大于负载因子，就扩容;
            AddCopyOf();
        }
    }
    public double Size() {
        return this.HashSizi*1.0/this.array.length;
    }
    public void AddCopyOf() {
        Node[] arraynext =new Node[this.array.length*2];
        for(int i=0;i<this.array.length;i++) {//获取每个数组的链表
            Node ret =array[i];
            while(ret!=null) {
                int index=ret.key % arraynext.length;
                Node str =new Node(ret.key,ret.val);//每次都重新创建一个节点来复制原链表
                if(arraynext[index]==null) {
                    arraynext[index] =str;
                }else {
                    Node uer =arraynext[index];
                    while(uer.next!=null) {
                        uer=uer.next;
                    }
                    uer.next=str;
                }
                ret=ret.next;
            }
        }
        this.array=arraynext;
    }
}
